

#include <gtk/gtk.h>
#include <stdio.h>
#include "support.h"
#include "window.h"
#include "regflag.h"
#include "keypad.h"
#include "memview.h"
#include "ioview.h"
#include "config.h"
#include "memfill.h"
#include "dialog.h"
#include "run.h"
#include "toolbar_second.h"

#include "statusbar.h"
#include "codeview.h"
#include "sourceview.h"

/*#################### Statics ####################*/
static void change_run_label(void);

/*###################### Globals #########################*/
gchar *mne_str,*op1_str,*op2_str;
static gint stop=0;
gint first_time=1;


/*################## Static functions ###################*/
static gint gsim_get_byte(void);
static gint gsim_get_word(void);
static gint gsim_get_byte_from_address(gint x_addr);
static gint gsim_set_byte_at_address(gint x_addr,gint byte);
static gint gsim_set_word_at_address(gint x_addr,gint word);
static gint gsim_get_memdata(void);
static gint gsim_set_memdata(gint byte);
static gint gsim_stack_push(gint data);
static gint gsim_stack_pop(void);
static gint gsim_get_port(gint port);
static void gsim_set_port(gint port,gint byte);


/*############ Get 1-byte data from the next memmory location ############*/
static gint gsim_get_byte(void)
{
	pc_value++; /*increment program counter*/
	if(pc_value>gsim_values.memend)
	{
		gsim_message(_("Address out of range"),GTK_MESSAGE_ERROR);
		return -1;
	}
	
	/*go to appropriate address in the memory*/
	memview_scroll_to_address(pc_value);
	
	/*get data now*/
	gint byte;
	gchar *byte_str;
	gtk_tree_model_get(memview_model,&memview_iter,1,&byte_str,-1);
	byte=make_int__(byte_str);
	g_free(byte_str);
	
	return byte;
}

/*######### Get 2-byte data from next memory location #########*/
static gint gsim_get_word(void)
{
	gint word;
	gint byte0,byte1;
	
	byte0=gsim_get_byte();
	if(byte0==-1)
		return -1;
	
	byte1=gsim_get_byte();
	if(byte1==-1)
		return -1;
	
	word=(byte1<<8)|byte0;
	return word;
}

/*########### Get 1-byte data from the address ###########*/
static gint gsim_get_byte_from_address(gint x_addr)
{
	if(x_addr<gsim_values.memstart||x_addr>gsim_values.memend)
	{
		gsim_message(_("Address out of range"),GTK_MESSAGE_ERROR);
		return -1;
	}
	
	/*get the corrsponding data*/
	GtkTreePath *path;
	GtkTreeIter iter;
	gint path_value,byte;
	gchar *byte_str,path_str[10];
	path_value=x_addr - gsim_values.memstart;
	snprintf(path_str,10,"%d",path_value);
	
	path=gtk_tree_path_new_from_string(path_str);
	gtk_tree_model_get_iter(memview_model,&iter,path);
	gtk_tree_model_get(memview_model,&iter,1,&byte_str,-1);
	byte=make_int__(byte_str);
	g_free(byte_str);
	
	return byte;
}

/*########### Set 1-byte data at the given address ############*/
static gint gsim_set_byte_at_address(gint x_addr,gint byte)
{
	if(x_addr<gsim_values.memstart||x_addr>gsim_values.memend)
	{
		gsim_message(_("Address out of range"),GTK_MESSAGE_ERROR);
		return -1;
	}
	
	/*get the corrsponding iter*/
	GtkTreePath *path;
	GtkTreeIter iter;
	gint path_value;
	gchar byte_str[3],path_str[10];
	path_value=x_addr - gsim_values.memstart;
	snprintf(path_str,10,"%d",path_value);
	
	path=gtk_tree_path_new_from_string(path_str);
	gtk_tree_model_get_iter(memview_model,&iter,path);
	
	/*set data now!*/
	snprintf(byte_str,3,"%02X",byte);
	gtk_list_store_set(GTK_LIST_STORE(memview_model),&iter,1,byte_str,-1);
	
	return 0;
}

/*################## Set 2-byte data at address #####################*/
static gint gsim_set_word_at_address(gint x_addr,gint word)
{
	gint byte0,byte1;
	
	byte0=word&0xff;
	byte1=word>>8;
	
	if(gsim_set_byte_at_address(x_addr,byte0)==-1)
		return -1;
	x_addr++;
	if(gsim_set_byte_at_address(x_addr,byte1)==-1)
		return -1;
	
	return 0;
}

/*################# Get data from address in HL pair ################*/
static gint gsim_get_memdata(void)
{
	set_hl();
	return gsim_get_byte_from_address(hl_value);
}

/*################ Set data at address in HL pair ##################*/
static gint gsim_set_memdata(gint byte)
{
	set_hl();
	return gsim_set_byte_at_address(hl_value,byte);
}

/*################ push data on stack ###################*/ 
static gint gsim_stack_push(gint data)
{
	if(sp_value-2<gsim_values.memstart)
	{
		gsim_message(_("Stack overflow"),GTK_MESSAGE_ERROR);
		return -1;
	}
	
	gsim_set_byte_at_address(--sp_value,data>>8);
	gsim_set_byte_at_address(--sp_value,data&0xff);
	
	return 0;
}

/*################ pop data from stack #################*/
static gint gsim_stack_pop(void)
{
	if(sp_value+2<gsim_values.memend)
	{
		gsim_message(_("Stack underflow"),GTK_MESSAGE_ERROR);
		return -1;
	}
	
	gint word,byte0,byte1;
	byte0=gsim_get_byte_from_address(sp_value++);
	byte1=gsim_get_byte_from_address(sp_value++);
	word=(byte1<<8)|byte0;
	
	return word;
}

/*############### Get data from the port ###################*/
static gint gsim_get_port(gint port)
{
	gchar port_str[10];
	gchar *byte_str;
	gint byte;
	
	snprintf(port_str,9,"%02X",port);
	ioview_scroll_to_port(port_str);
	
	gtk_tree_model_get(ioview_model,&ioview_iter,1,&byte_str,-1);
	byte=make_int__(byte_str);
	g_free(byte_str);
	
	return byte;
}

/*############### Set data at port ##################*/
static void gsim_set_port(gint port,gint byte)
{
	gchar port_str[10];
	gchar byte_str[3];
	
	snprintf(port_str,9,"%02X",port);
	ioview_scroll_to_port(port_str);
	
	snprintf(byte_str,3,"%02X",byte);
	gtk_list_store_set(GTK_LIST_STORE(ioview_model),&ioview_iter,1,byte_str,-1);
}

/*###############################################################
 * Here are the actual functions for simulating the instructions*
 *##############################################################*/

gint nop_call(void)
{
	gsim_set_registers();
	pc_value++;
	gsim_set_entries();
	mne_str= "NOP";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint aci_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ACI";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint adi_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADI";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint sbi_8_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	mne_str= "SBI";
	op1_str= make_str__(x,2);
	op2_str= "";
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	return 0;
}

gint sui_8_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	mne_str= "SUI";
	op1_str= make_str__(x,2);
	op2_str= "";
	x=(~(x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	return 0;
}

gint hlt_call(void)
{
	mne_str= "HLT";
	op1_str= "";
	op2_str= "";
	return -1;
}

gint adc_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint adc_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "C";
	op2_str= "";
	return 0;
}
gint adc_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "D";
	op2_str= "";
	return 0;
}
gint adc_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "E";
	op2_str= "";
	return 0;
}
gint adc_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "H";
	op2_str= "";
	return 0;
}
gint adc_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "L";
	op2_str= "";
	return 0;
}
gint adc_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "M";
	op2_str= "";
	return 0;
}
gint adc_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	set_aux_flag(x+carry_value);
	a_value=a_value+x+carry_value;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADC";
	op1_str= "A";
	op2_str= "";
	return 0;
}


gint add_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint add_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint add_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint add_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint add_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint add_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint add_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint add_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ADD";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint sbb_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint sbb_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint sbb_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint sbb_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint sbb_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint sbb_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint sbb_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint sbb_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	x=((~(x+carry_value))+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SBB";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint sub_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "B";
	op2_str= "";
	return 0;
}


gint sub_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint sub_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint sub_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint sub_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint sub_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint sub_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint sub_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "SUB";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint cma_call(void)
{
	gsim_set_registers();
	a_value=~(a_value)&0xff;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMA";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint cmc_call(void)
{
	gsim_set_registers();
	comp_carry();
	pc_value++;
	gsim_set_entries();
	mne_str= "CMC";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint cpi_8_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	mne_str= "CPI";
	op1_str= make_str__(x,2);
	op2_str= "";
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	return 0;
}

gint cmp_b_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=b_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint cmp_c_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=c_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "C";
	op2_str= "";
	return 0;
}
gint cmp_d_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=d_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "D";
	op2_str= "";
	return 0;
}
gint cmp_e_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=e_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "E";
	op2_str= "";
	return 0;
}
gint cmp_h_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=h_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "H";
	op2_str= "";
	return 0;
}
gint cmp_l_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=l_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "L";
	op2_str= "";
	return 0;
}
gint cmp_a_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=a_value;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint cmp_m_call(void)
{
	gint x,y;
	gsim_set_registers();
	y=a_value;
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	x=((~x)+1)&0xff;
	set_aux_flag(x);
	a_value=a_value+x;
	set_carry_flag();
	if(x)
		comp_carry();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	a_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "CMP";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint daa_call(void)
{
	gsim_set_registers();
	
	if((a_value&0xf)>0x9||aux_value)
	{		
		if((a_value&0xf0)>0x90||carry_value)
		{
			set_aux_flag(0x66);
			a_value=a_value+0x66;
		}
		else
		{
			set_aux_flag(0x6);
			a_value=a_value+0x6;
		}
	}
	else if((a_value&0xf0)>0x90||carry_value)
	{
		a_value=a_value+0x60;
	}
	
	set_carry_flag();
	set_zero_flag();
	set_parity_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "DAA";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint dad_h_call(void)
{
	gsim_set_registers();
	set_hl();
	hl_value=hl_value+hl_value;
	if(hl_value>>16)
		carry_value=1;
	else
		carry_value=0;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "DAD";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint dad_b_call(void)
{
	gsim_set_registers();
	set_hl();
	set_bc();
	hl_value=hl_value+bc_value;
	if(hl_value>>16)
		carry_value=1;
	else
		carry_value=0;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "DAD";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint dad_d_call(void)
{
	gsim_set_registers();
	set_hl();
	set_de();
	hl_value=hl_value+de_value;
	if(hl_value>>16)
		carry_value=1;
	else
		carry_value=0;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "DAD";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint dad_sp_call(void)
{
	gsim_set_registers();
	set_hl();
	hl_value=hl_value+sp_value;
	if(hl_value>>16)
		carry_value=1;
	else
		carry_value=0;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "DAD";
	op1_str= "SP";
	op2_str= "";
	return 0;
}

gint dcr_b_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=b_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	b_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint inr_b_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=b_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	b_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint dcr_c_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=c_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	c_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint inr_c_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=c_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	c_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint dcr_d_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=d_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	d_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint inr_d_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=d_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	d_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint dcr_e_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=e_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	e_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint inr_e_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=e_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	e_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint dcr_h_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=h_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	h_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint inr_h_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=h_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	h_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint dcr_l_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=l_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	l_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint inr_l_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=l_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	l_value=a_value;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "L";
	op2_str= "";
	return 0;
}


gint dcr_a_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=a_value;
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	a_value=a_value;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint inr_a_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=a_value;
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	a_value=a_value;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint dcr_m_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=gsim_get_memdata();
	if(a_value==-1)
	{
		a_value=x;
		return -1;
	}
	set_aux_flag(0xff);
	a_value-- ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	gint s;   
	s=gsim_set_memdata(a_value);
	if(s==-1)
		return -1;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCR";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint inr_m_call(void)
{
	gsim_set_registers();
	gint x;
	x=a_value;
	a_value=gsim_get_memdata();
	if(a_value==-1)
	{
		a_value=x;
		return -1;
	}
	set_aux_flag(1);
	a_value++ ;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	gint s;   
	s=gsim_set_memdata(a_value);
	if(s==-1)
		return -1;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "INR";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint dcx_b_call(void)
{
	gsim_set_registers();
	set_bc();
	bc_value--;
	get_bc();
	pc_value++;
	gsim_set_entries();
	mne_str= "DCX";
	op1_str= "B";
	op2_str= "";
	return 0;
}


gint inx_b_call(void)
{
	gsim_set_registers();
	set_bc();
	bc_value++;
	get_bc();
	pc_value++;
	gsim_set_entries();
	mne_str= "INX";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint dcx_d_call(void)
{
	gsim_set_registers();
	set_de();
	de_value--;
	get_de();
	pc_value++;
	gsim_set_entries();
	mne_str= "DCX";
	op1_str= "D";
	op2_str= "";
	return 0;
}


gint inx_d_call(void)
{
	gsim_set_registers();
	set_de();
	de_value++;
	get_de();
	pc_value++;
	gsim_set_entries();
	mne_str= "INX";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint dcx_h_call(void)
{
	gsim_set_registers();
	set_hl();
	hl_value--;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "DCX";
	op1_str= "H";
	op2_str= "";
	return 0;
}


gint inx_h_call(void)
{
	gsim_set_registers();
	set_hl();
	hl_value++;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "INX";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint dcx_sp_call(void)
{
	gsim_set_registers();
	sp_value--;
	pc_value++;
	gsim_set_entries();
	mne_str= "DCX";
	op1_str= "SP";
	op2_str= "";
	return 0;
}


gint inx_sp_call(void)
{
	gsim_set_registers();
	sp_value++;
	pc_value++;
	gsim_set_entries();
	mne_str= "INX";
	op1_str= "SP";
	op2_str= "";
	return 0;
}

gint stc_call(void)
{
	gsim_set_registers();
	carry_value=1;
	pc_value++;
	gsim_set_entries();
	mne_str= "STC";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint ani_8_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANI";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint ana_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint ana_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint ana_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint ana_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint ana_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint ana_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint ana_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint ana_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	a_value=a_value & x;
	carry_value=0;
	aux_value=1;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ANA";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint ori_8_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORI";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint ora_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint ora_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint ora_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint ora_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint ora_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint ora_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint ora_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint ora_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	a_value=a_value | x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "ORA";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint xri_8_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRI";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint xra_b_call(void)
{
	gint x;
	gsim_set_registers();
	x=b_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "";
	op2_str= "";
	return 0;
}


gint xra_c_call(void)
{
	gint x;
	gsim_set_registers();
	x=c_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "C";
	op2_str= "";
	return 0;
}

gint xra_d_call(void)
{
	gint x;
	gsim_set_registers();
	x=d_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint xra_e_call(void)
{
	gint x;
	gsim_set_registers();
	x=e_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "E";
	op2_str= "";
	return 0;
}

gint xra_h_call(void)
{
	gint x;
	gsim_set_registers();
	x=h_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint xra_l_call(void)
{
	gint x;
	gsim_set_registers();
	x=l_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "L";
	op2_str= "";
	return 0;
}

gint xra_a_call(void)
{
	gint x;
	gsim_set_registers();
	x=a_value;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "A";
	op2_str= "";
	return 0;
}

gint xra_m_call(void)
{
	gint x;
	gsim_set_registers();
	x=gsim_get_memdata(); 
	if(x==-1) 
		return -1;
	a_value=a_value ^ x;
	carry_value=0;
	aux_value=0;
	set_parity_flag();
	set_zero_flag();
	set_sign_flag();
	pc_value++;
	gsim_set_entries();
	mne_str= "XRA";
	op1_str= "M";
	op2_str= "";
	return 0;
}

gint ral_call(void)
{
	gsim_set_registers();
	a_value=a_value<<1;
	a_value=a_value | carry_value;
	if(a_value&0x100)
		carry_value=1;
	else
		carry_value=0;
	pc_value++;
	gsim_set_entries();
	mne_str= "RAL";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rar_call(void)
{
	gsim_set_registers();
	a_value=a_value | (carry_value<<8);
	if(a_value&0x1)
		carry_value=1;
	else
		carry_value=0;
	a_value=a_value>>1;
	pc_value++;
	gsim_set_entries();
	mne_str= "RAR";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rlc_call(void)
{
	gsim_set_registers();
	a_value=a_value<<1;
	
	if(a_value&0x100)
		carry_value=1;
	else
		carry_value=0;
	a_value=a_value | carry_value;
	pc_value++;
	gsim_set_entries();
	mne_str= "RLC";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rrc_call(void)
{
	gsim_set_registers();
	if(a_value&0x1)
		carry_value=1;
	else
		carry_value=0;
	a_value=a_value | (carry_value<<8);
	a_value=a_value>>1;
	pc_value++;
	gsim_set_entries();
	mne_str= "RRC";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint di_call(void)
{
	gsim_set_registers();
	ei_value=0;
	rst55_value=0;
	rst65_value=0;
	rst75_value=0;
	pc_value++;
	gsim_set_entries();
	mne_str= "DI";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint ei_call(void)
{
	gsim_set_registers();
	ei_value=1;
	rst55_value=1;
	rst65_value=1;
	rst75_value=1;
	pc_value++;
	gsim_set_entries();
	mne_str= "EI";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint jmp_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;  
	pc_value=x;
	gsim_set_entries();
	mne_str= "JMP";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jc_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;  
	if(carry_value)
	        pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JC";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jnc_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(!carry_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JNC";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jp_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(!sign_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JP";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jm_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(sign_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JM";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jpe_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(parity_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JPE";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jpo_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(!parity_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JPO";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jz_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(zero_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JZ";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint jnz_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(!zero_value)
	         pc_value=x;
	else
			pc_value++;
	gsim_set_entries();
	mne_str= "JNZ";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint call_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=x;
	gsim_set_entries();
	mne_str= "CALL";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cc_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(carry_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CC";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cnc_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(!carry_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CNC";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cz_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(zero_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CZ";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cnz_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(!zero_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CNZ";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cm_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(sign_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CM";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cp_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(!sign_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CP";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cpe_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(parity_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CPE";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint cpo_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	pc_value++;
	if(!parity_value)
	{
		if(gsim_stack_push(pc_value)==-1)
			return -1;
		pc_value=x;
	}
	gsim_set_entries();
	mne_str= "CPO";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint ret_call(void)
{
	gsim_set_registers();
	pc_value=gsim_stack_pop();   
	if(pc_value==-1)  
		return -1;
	gsim_set_entries();
	mne_str= "RET";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rc_call(void)
{
	gsim_set_registers();
	if(carry_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RC";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rnc_call(void)
{
	gsim_set_registers();
	if(!carry_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RNC";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rp_call(void)
{
	gsim_set_registers();
	if(!sign_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RP";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rm_call(void)
{
	gsim_set_registers();
	if(sign_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RM";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rz_call(void)
{
	gsim_set_registers();
	if(zero_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RZ";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rnz_call(void)
{
	gsim_set_registers();
	if(!zero_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RNZ";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rpe_call(void)
{
	gsim_set_registers();
	if(parity_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RPE";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint rpo_call(void)
{
	gsim_set_registers();
	if(!parity_value)
	{  
		pc_value=gsim_stack_pop();   
		if(pc_value==-1)  
			return -1; 
	}
	else
		pc_value++;
	gsim_set_entries();
	mne_str= "RPO";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint mov_b_b_call(void)
{
	gsim_set_registers();
	b_value=b_value;
	pc_value++;
	gsim_set_entries();
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "B";	
	return 0;
}

gint mov_b_c_call(void)
{
	gsim_set_registers();
	b_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "C";	
	return 0;
}

gint mov_b_d_call(void)
{
	gsim_set_registers();
	b_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "D";	
	return 0;
}

gint mov_b_e_call(void)
{
	gsim_set_registers();
	b_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "E";	
	return 0;
}

gint mov_b_h_call(void)
{
	gsim_set_registers();
	b_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "H";	
	return 0;
}

gint mov_b_l_call(void)
{
	gsim_set_registers();
	b_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "L";	
	return 0;
}

gint mov_b_a_call(void)
{
	gsim_set_registers();
	b_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "A";	
	return 0;
}

gint mov_b_m_call(void)
{
	gsim_set_registers();
	b_value=gsim_get_memdata();
	if(b_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "B";
	op2_str= "M";	
	return 0;
}

gint mov_c_b_call(void)
{
	gsim_set_registers();
	c_value=b_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "B";	
	return 0;
}

gint mov_c_c_call(void)
{
	gsim_set_registers();
	c_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "C";	
	return 0;
}

gint mov_c_d_call(void)
{
	gsim_set_registers();
	c_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "D";	
	return 0;
}

gint mov_c_e_call(void)
{
	gsim_set_registers();
	c_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "E";	
	return 0;
}

gint mov_c_h_call(void)
{
	gsim_set_registers();
	c_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "H";	
	return 0;
}

gint mov_c_l_call(void)
{
	gsim_set_registers();
	c_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "L";	
	return 0;
}

gint mov_c_a_call(void)
{
	gsim_set_registers();
	c_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "A";	
	return 0;
}

gint mov_c_m_call(void)
{
	gsim_set_registers();
	c_value=gsim_get_memdata();
	if(c_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "C";
	op2_str= "M";	
	return 0;
}

gint mov_d_b_call(void)
{
	gsim_set_registers();
	d_value=b_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "B";	
	return 0;
}

gint mov_d_c_call(void)
{
	gsim_set_registers();
	d_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "C";	
	return 0;
}

gint mov_d_d_call(void)
{
	gsim_set_registers();
	d_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "D";	
	return 0;
}

gint mov_d_e_call(void)
{
	gsim_set_registers();
	d_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "E";	
	return 0;
}

gint mov_d_h_call(void)
{
	gsim_set_registers();
	d_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "H";	
	return 0;
}

gint mov_d_l_call(void)
{
	gsim_set_registers();
	d_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "L";	
	return 0;
}

gint mov_d_a_call(void)
{
	gsim_set_registers();
	d_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "A";	
	return 0;
}

gint mov_d_m_call(void)
{
	gsim_set_registers();
	d_value=gsim_get_memdata();
	if(d_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "D";
	op2_str= "M";	
	return 0;
}

gint mov_e_b_call(void)
{
	gsim_set_registers();
	e_value=b_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "B";	
	return 0;
}

gint mov_e_c_call(void)
{
	gsim_set_registers();
	e_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "C";	
	return 0;
}

gint mov_e_d_call(void)
{
	gsim_set_registers();
	e_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "D";	
	return 0;
}

gint mov_e_e_call(void)
{
	gsim_set_registers();
	e_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "E";	
	return 0;
}

gint mov_e_h_call(void)
{
	gsim_set_registers();
	e_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "H";	
	return 0;
}

gint mov_e_l_call(void)
{
	gsim_set_registers();
	e_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "L";	
	return 0;
}

gint mov_e_a_call(void)
{
	gsim_set_registers();
	e_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "A";	
	return 0;
}

gint mov_e_m_call(void)
{
	gsim_set_registers();
	e_value=gsim_get_memdata();
	if(e_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "M";	
	return 0;
}

gint mov_h_b_call(void)
{
	gsim_set_registers();
	h_value=b_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "B";	
	return 0;
}

gint mov_h_c_call(void)
{
	gsim_set_registers();
	h_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "C";
	return 0;
}

gint mov_h_d_call(void)
{
	gsim_set_registers();
	h_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "D";
	return 0;
}

gint mov_h_e_call(void)
{
	gsim_set_registers();
	h_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "E";
	return 0;
}

gint mov_h_h_call(void)
{
	gsim_set_registers();
	h_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "H";
	return 0;
}

gint mov_h_l_call(void)
{
	gsim_set_registers();
	h_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "L";
	return 0;
}

gint mov_h_a_call(void)
{
	gsim_set_registers();
	h_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "A";
	return 0;
}

gint mov_h_m_call(void)
{
	gsim_set_registers();
	h_value=gsim_get_memdata();
	if(h_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "H";
	op2_str= "M";
	return 0;
}

gint mov_l_b_call(void)
{
	gsim_set_registers();
	l_value=b_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "B";
	return 0;
}

gint mov_l_c_call(void)
{
	gsim_set_registers();
	l_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "C";
	return 0;
}


gint mov_l_d_call(void)
{
	gsim_set_registers();
	l_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "D";
	return 0;
}


gint mov_l_e_call(void)
{
	gsim_set_registers();
	l_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "E";
	return 0;
}


gint mov_l_h_call(void)
{
	gsim_set_registers();
	l_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "H";
	return 0;
}


gint mov_l_l_call(void)
{
	gsim_set_registers();
	l_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "L";
	return 0;
}


gint mov_l_a_call(void)
{
	gsim_set_registers();
	l_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "A";
	return 0;
}


gint mov_l_m_call(void)
{
	gsim_set_registers();
	l_value=gsim_get_memdata();
	if(l_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "L";
	op2_str= "M";
	return 0;
}

gint mov_a_b_call(void)
{
	gsim_set_registers();
	a_value=b_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "B";
	return 0;
}

gint mov_a_c_call(void)
{
	gsim_set_registers();
	a_value=c_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "C";
	return 0;
}


gint mov_a_d_call(void)
{
	gsim_set_registers();
	a_value=d_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "D";
	return 0;
}


gint mov_a_e_call(void)
{
	gsim_set_registers();
	a_value=e_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "E";
	op2_str= "";
	return 0;
}


gint mov_a_h_call(void)
{
	gsim_set_registers();
	a_value=h_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "H";
	return 0;
}


gint mov_a_l_call(void)
{
	gsim_set_registers();
	a_value=l_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "L";
	return 0;
}


gint mov_a_a_call(void)
{
	gsim_set_registers();
	a_value=a_value;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "A";
	return 0;
}


gint mov_a_m_call(void)
{
	gsim_set_registers();
	a_value=gsim_get_memdata();
	if(a_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "A";
	op2_str= "M";
	return 0;
}

gint mov_m_b_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(b_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "B";
	return 0;
}

gint mov_m_c_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(c_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "C";
	return 0;
}


gint mov_m_d_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(d_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "D";
	return 0;
}


gint mov_m_e_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(e_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "E";
	return 0;
}

gint mov_m_h_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(h_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "H";
	return 0;
}

gint mov_m_l_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(l_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "L";
	return 0;
}

gint mov_m_a_call(void)
{
	gsim_set_registers();
	gint s;   
	s=gsim_set_memdata(a_value);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();   
	mne_str= "MOV";
	op1_str= "M";
	op2_str= "A";
	return 0;
}

gint mvi_b_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	b_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "B";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_c_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	c_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "C";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_d_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	d_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "D";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_e_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	e_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "E";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_h_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	h_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "H";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_l_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	l_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "L";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_a_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	a_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "A";
	op2_str= make_str__(x,2);
	return 0;
}

gint mvi_m_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	gint s;   
	s=gsim_set_memdata(x);
	if(s==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "MVI";
	op1_str= "M";
	op2_str= make_str__(x,2);
	return 0;
}

gint in_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	a_value=gsim_get_port(x);
	pc_value++;
	gsim_set_entries();
	mne_str= "IN";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint out_8_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_byte();  
	if(x==-1)    
		return -1;
	gsim_set_port(x,a_value);
	pc_value++;
	gsim_set_entries();
	mne_str= "OUT";
	op1_str= make_str__(x,2);
	op2_str= "";
	return 0;
}

gint lda_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word();  
	if(x==-1)    
		return -1;
	a_value=gsim_get_byte_from_address(x);
	if(a_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "LDA";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint ldax_b_call(void)
{
	gsim_set_registers();
	set_bc();
	a_value=gsim_get_byte_from_address(bc_value);
	if(a_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "LDAX";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint ldax_d_call(void)
{
	gsim_set_registers();
	set_de();
	a_value=gsim_get_byte_from_address(de_value);
	if(a_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "LDAX";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint lhld_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word(); 
	if(x==-1) 
		return -1;
	l_value=gsim_get_byte_from_address(x);
	if(l_value==-1)
		return -1;
	h_value=gsim_get_byte_from_address(x+1);
	if(h_value==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "LHLD";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint lxi_h_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word(); 
	if(x==-1) 
		return -1;
	hl_value=x;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "LXI";
	op1_str= "H";
	op2_str= make_str__(x,4);
	return 0;
}

gint lxi_b_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word(); 
	if(x==-1) 
		return -1;
	bc_value=x;
	get_bc();
	pc_value++;
	gsim_set_entries();
	mne_str= "LXI";
	op1_str= "B";
	op2_str= make_str__(x,4);
	return 0;
}

gint lxi_d_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word(); 
	if(x==-1) 
		return -1;
	de_value=x;
	get_de();
	pc_value++;
	gsim_set_entries();
	mne_str= "LXI";
	op1_str= "D";
	op2_str= make_str__(x,4);
	return 0;
}

gint lxi_sp_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word(); 
	if(x==-1) 
		return -1;
	sp_value=x;
	pc_value++;
	gsim_set_entries();
	mne_str= "LXI";
	op1_str= "SP";
	op2_str= make_str__(x,4);
	return 0;
}

gint pchl_call(void)
{
	gsim_set_registers();
	set_hl();
	pc_value=hl_value;
	gsim_set_entries();
	mne_str= "PCHL";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint pop_b_call(void)
{
	gsim_set_registers();
	bc_value=gsim_stack_pop();
	if(bc_value==-1)
		return -1;
	get_bc();
	pc_value++;
	gsim_set_entries();
	mne_str= "POP";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint pop_d_call(void)
{
	gsim_set_registers();
	de_value=gsim_stack_pop();
	if(de_value==-1)
		return -1;
	get_de();
	pc_value++;
	gsim_set_entries();
	mne_str= "POP";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint pop_h_call(void)
{
	gsim_set_registers();
	hl_value=gsim_stack_pop();
	if(hl_value==-1)
		return -1;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "POP";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint pop_psw_call(void)
{
	gsim_set_registers();
	psw_value=gsim_stack_pop();
	if(psw_value==-1)
		return -1;
	get_psw();
	pc_value++;
	gsim_set_entries();
	mne_str= "POP";
	op1_str= "PSW";
	op2_str= "";
	return 0;
}

gint push_b_call(void)
{
	gsim_set_registers();
	set_bc();
	if(gsim_stack_push(bc_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "PUSH";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint push_d_call(void)
{
	gsim_set_registers();
	set_de();
	if(gsim_stack_push(de_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "PUSH";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint push_h_call(void)
{
	gsim_set_registers();
	set_hl();
	if(gsim_stack_push(hl_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "PUSH";
	op1_str= "H";
	op2_str= "";
	return 0;
}

gint push_psw_call(void)
{
	gsim_set_registers();
	set_psw();
	if(gsim_stack_push(psw_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "PUSH";
	op1_str= "PSW";
	op2_str= "";
	return 0;
}

gint shld_16_call(void)
{
	gsim_set_registers();
	set_hl();
	gint x;
	x=gsim_get_word(); 
	if (x==-1) 
		return -1;
	if(gsim_set_word_at_address(x,hl_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "SHLD";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint sphl_call(void)
{
	gsim_set_registers();
	set_hl();
	sp_value=hl_value;
	pc_value++;
	gsim_set_entries();
	mne_str= "SPHL";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint sta_16_call(void)
{
	gsim_set_registers();
	gint x;
	x=gsim_get_word(); 
	if(x==-1) 
		return -1;
	if(gsim_set_byte_at_address(x,a_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "STA";
	op1_str= make_str__(x,4);
	op2_str= "";
	return 0;
}

gint stax_b_call(void)
{
	gsim_set_registers();
	set_bc();
	if(gsim_set_byte_at_address(bc_value,a_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "STAX";
	op1_str= "B";
	op2_str= "";
	return 0;
}

gint stax_d_call(void)
{
	gsim_set_registers();
	set_de();
	if(gsim_set_byte_at_address(de_value,a_value)==-1)
		return -1;
	pc_value++;
	gsim_set_entries();
	mne_str= "STAX";
	op1_str= "D";
	op2_str= "";
	return 0;
}

gint xchg_call(void)
{
	gsim_set_registers();
	gint x,y;
	x=h_value;
	y=l_value;
	h_value=d_value;
	l_value=e_value;
	d_value=x;
	e_value=y;
	pc_value++;
	gsim_set_entries();
	mne_str= "XCHG";
	op1_str= "";
	op2_str= "";
	return 0;
}
 
gint xthl_call(void)
{
	gsim_set_registers();
	set_hl();
	gint x;
	x=gsim_stack_pop();
	if(x==-1)
		return -1;
	if(gsim_stack_push(hl_value)==-1)
		return -1;
	hl_value=x;
	get_hl();
	pc_value++;
	gsim_set_entries();
	mne_str= "XTHL";
	op1_str= "";
	op2_str= "";
	return 0;
}


/*RIM , SIM CALLBACKS DO NOTHING
THEY ARE THERE FOR THE SHAKE OF 
COMPLETENESS*/

gint rim_call(void)
{
	gsim_set_registers();
	a_value=((sid_value<<7)|(rst75_value<<6)|(rst65_value<<5)|(rst55_value<<4)|(ei_value<<3)|(mask75_value<<2)|(mask65_value<<1)|(mask55_value))&0xff;
	pc_value++;
	gsim_set_entries();
	mne_str= "RIM";
	op1_str= "";
	op2_str= "";
	return 0;
}

gint sim_call(void)
{
	gsim_set_registers();
	sod_value=(a_value>>7)&0x1;
	sde_value=(a_value>>6)&0x1;
	rst55_value=(a_value>>4)&0x1;
	mse_value=(a_value>>3)&0x1;
	mask75_value=(a_value>>2)&0x1;
	mask65_value=(a_value>>1)&0x1;
	mask55_value=(a_value)&0x1;
	pc_value++;
	gsim_set_entries();
	mne_str= "SIM";
	op1_str= "";
	op2_str= "";
	return 0;
}


gint rst_0_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0000;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "0";
	op2_str= "";
	return 0;
}

gint rst_1_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0008;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "1";
	op2_str= "";
	return 0;
}

gint rst_2_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0010;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "2";
	op2_str= "";
	return 0;
}

gint rst_3_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0018;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "3";
	op2_str= "";
	return 0;
}

gint rst_4_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0020;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "4";
	op2_str= "";
	return 0;
}

gint rst_5_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0028;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "5";
	op2_str= "";
	return 0;
}

gint rst_6_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0030;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "6";
	op2_str= "";
	return 0;
}

gint rst_7_call(void)
{
	gsim_set_registers();
	if(gsim_stack_push(++pc_value)==-1)
		return -1;
	pc_value=0x0038;
	gsim_set_entries();
	mne_str= "RST";
	op1_str= "7";
	op2_str= "";
	return 0;
}

/*a none existing code's callback*/
gint code_error_call(void)
{
	gsim_message("Invalid Instruction code.\nCheck if start address is correct",GTK_MESSAGE_ERROR);
	mne_str= "ERROR!";
	op1_str= "";
	op2_str= "";
	return -1;
}

#include "run_lookup.h"

/*################# Change run button label #############*/
static void change_run_label(void)
{
	if(stop==0)
	{
		gtk_button_set_label(GTK_BUTTON(run),"gtk-stop");
		stop=1;
	}
	else
	{
		gtk_button_set_label(GTK_BUTTON(run),"run");
		stop=0;
	}
	gtk_widget_show(run);
}

/*################## Run button clicked #################*/
void gsim_run()
{
	if(stop) /*if stop is active*/
	{
		change_run_label();
		return;
	}
	
	static gint prev_breakpint,break_addr;
	
	if(!prev_breakpint) /*if run is called after a breakpoint*/
	{
		reset_regflag();

		/*get the program counter value*/
		pc_value=make_int__(gtk_entry_get_text(GTK_ENTRY(start_address)));
		if(pc_value<gsim_values.memstart||pc_value>gsim_values.memend)
		{
			pc_value=gsim_values.memstart;
			gsim_set_entries();
			gsim_message(_("Please provide a start address in appropriate memory range"),GTK_MESSAGE_ERROR);
			return;
		}
		/*show the source view*/
		state_sourceview=0;
		show_hide_sourceview();
		gsim_reset_sourceview();
	}
	else
	{
	//	pc_value=make_int__(gtk_entry_get_text(GTK_ENTRY(start_address)));
		if(pc_value<gsim_values.memstart||pc_value>gsim_values.memend)
		{
			pc_value=gsim_values.memstart;
			gsim_set_entries();
			gsim_message(_("Please provide a start address in appropriate memory range"),GTK_MESSAGE_ERROR);
			return;
		}
	}
	
	gsim_set_entries();
	change_run_label(); /*make stop active*/
	
	
	/*enter in the run loop*/
	for(;;)
	{
		if(pc_value<gsim_values.memstart||pc_value>gsim_values.memend)
		{
			pc_value=gsim_values.memstart;
			gsim_set_entries();
			gsim_message(_("Address not in the range"),GTK_MESSAGE_ERROR);
			stop=1;
			change_run_label();
			return;
		}
		
		/*set the iterator to the address*/
		gint back_scroll=pc_value;
		memview_scroll_to_address(pc_value);
		
		gchar *code_str,*addr;
		gint code;
		gtk_tree_model_get(memview_model,&memview_iter,0,&addr,1,&code_str,-1);
		code=make_int__(code_str);
		g_free(code_str);
		
		/*find out the path of source row in appropriate page*/
		struct codeview_ref_info *new_ref;
		new_ref=g_object_get_data(codeview_ref,addr);
		if(new_ref!=NULL&&gtk_notebook_page_num(GTK_NOTEBOOK(codeview_notebook),new_ref->page)!=-1)
		{
			if(new_ref->page!=current_page)
			{
				gint n=gtk_notebook_page_num(GTK_NOTEBOOK(codeview_notebook),new_ref->page);
				gtk_notebook_set_current_page(GTK_NOTEBOOK(codeview_notebook),n);
				while(gtk_events_pending())
					gtk_main_iteration();
				
				gfloat delay;
				for(delay=0;delay<4000000;delay++);
			}
			
			if(gtk_tree_model_get_iter_from_string(current_code_model,&current_code_iter,new_ref->path))
			{
				/*set codeview marker*/
				remove_marker();
				scroll_to_row();
				gtk_tree_selection_select_iter(current_code_selection,&current_code_iter);
				
			}
		
			/*if there is breakpoint*/
			GdkPixbuf *break_buf;
			gtk_tree_model_get(current_code_model,&current_code_iter,BR_COL,&break_buf,-1);
			if(break_buf)
			{
				if(!prev_breakpint)
				{
					gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gsim_progress),0);
					change_run_label();
					prev_breakpint=1;
					break_addr=pc_value;
					return;
				}
			}
		}
		prev_breakpint=0; /*clear any breakpoint*/
		
		/*extract the code and call approprite function*/
		if((*run_lookup_table[code].func)()==-1)
		{
			gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gsim_progress),0);
			GString *str;
			str=g_string_new("");
			g_string_append_printf(str,"\t%s\t\t%s\t\t%s\t\t%s\n",addr,mne_str,op1_str,op2_str);
			gtk_text_buffer_insert_at_cursor(sourceview_buffer,str->str,str->len);
			sourceview_scroll_end();
			g_string_free(str,TRUE);
			g_free(addr);
			stop=1;
			change_run_label();
			return;
		}
		
		/*add the current context in source window*/
		GString *str;
		str=g_string_new("");
		g_string_append_printf(str,"\t%s\t\t%s\t\t%s\t\t%s\n",addr,mne_str,op1_str,op2_str);
		gtk_text_buffer_insert_at_cursor(sourceview_buffer,str->str,str->len);
		sourceview_scroll_end();
		g_string_free(str,TRUE);
		g_free(addr);
		
		/*back scroll to code cell*/
		memview_scroll_to_address(back_scroll);
		
		/*do one main iteration*/
		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gsim_progress),1);
		while(gtk_events_pending())
			gtk_main_iteration();
		gfloat delay;
		for(delay=0;delay<2000000;delay++);
			
		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gsim_progress),0);
		while(gtk_events_pending())
			gtk_main_iteration();
		for(delay=0;delay<2000000;delay++);
			
		/*check if user cancel the request*/
		if(stop==0)
		{
			gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gsim_progress),0);
			return;
		}
	}
	return;
}

/*######################## Step through instructions #####################*/
void gsim_step(void)
{	
	first_time=0;
	if(first_time)    /*if it is first time set pc to start address*/
	{
		pc_value=make_int__(gtk_entry_get_text(GTK_ENTRY(start_address)));
		gsim_set_entries();
		first_time=0;
		gsim_reset_sourceview();
	}
	else
		gsim_set_registers();
	
	if(pc_value<gsim_values.memstart||pc_value>gsim_values.memend)
	{
		pc_value=gsim_values.memstart;
		gsim_set_entries();
		gsim_message(_("Address not in the range"),GTK_MESSAGE_ERROR);
		first_time=1;
		return;
	}
	
	/*show the source view*/
	state_sourceview=0;
	show_hide_sourceview();
		
	/*set the iterator to the address*/
	gint back_scroll=pc_value;
	memview_scroll_to_address(pc_value);
		
	gchar *code_str,*addr;
	gint code;
	gtk_tree_model_get(memview_model,&memview_iter,0,&addr,1,&code_str,-1);
	code=make_int__(code_str);
	g_free(code_str);
		
	/*find out the path of source row in appropriate page*/
	struct codeview_ref_info *new_ref;
	new_ref=g_object_get_data(codeview_ref,addr);
	if(new_ref!=NULL)
	{
		if(new_ref->page!=current_page)
		{
			gint n=gtk_notebook_page_num(GTK_NOTEBOOK(codeview_notebook),new_ref->page);
			gtk_notebook_set_current_page(GTK_NOTEBOOK(codeview_notebook),n);
		}
		
		if(gtk_tree_model_get_iter_from_string(current_code_model,&current_code_iter,new_ref->path))
		{
			/*set codeview marker*/
			remove_marker();
			scroll_to_row();
			gtk_tree_selection_select_iter(current_code_selection,&current_code_iter);
		}
	}
		
	/*extract the code and call approprite function*/
	if((*run_lookup_table[code].func)()==-1)
	{
		GString *str;
		str=g_string_new("");
		g_string_append_printf(str,"\t%s\t\t%s\t\t%s\t\t%s\n",addr,mne_str,op1_str,op2_str);
		gtk_text_buffer_insert_at_cursor(sourceview_buffer,str->str,str->len);
		sourceview_scroll_end();
		g_string_free(str,TRUE);
		g_free(addr);
		return;
	}
		
	/*add the current context in source window*/
	GString *str;
	str=g_string_new("");
	g_string_append_printf(str,"\t%s\t\t%s\t\t%s\t\t%s\n",addr,mne_str,op1_str,op2_str);
	gtk_text_buffer_insert_at_cursor(sourceview_buffer,str->str,str->len);
	sourceview_scroll_end();
	g_string_free(str,TRUE);
	g_free(addr);
	
	/*back scrool to the code cell*/
	memview_scroll_to_address(back_scroll);
		
	return;
}
